import { IOverlayDataSet } from '@/types/overlay';
import { IMultiData } from '@/types/multi_data';
import { IGeoFile } from '@/types/geofile';
import useResourceHelper from './ui/useResourceHelper';

interface IPreviewType {
    type: IMultiData['type'] | null
    url: string
    can: boolean
}

/**
* @title  get multi data preview url util
*/
function usePreview() {

    const {
        getStaticUrl
    } = useResourceHelper()

    function getPreviewType(data: IMultiData): IPreviewType {

        const {
            details,
            type
        } = data


        const url = getStaticUrl(details.thumbnails)

        if (type == 'tif' && details.thumbnails) {

            return {
                can: true,
                type: type,
                url: url
            }
        } else {
            return {
                can: false,
                type: null,
                url: ''
            }
        }

    }

    function canPreview(data: IMultiData) {
        const {
            details
        } = data

        return details && !!details.thumbnails
    }

    function canOverlaySnapPreview(data: IOverlayDataSet) {
        const {
            features
        } = data

        if (features && features.length > 0) {
            return true
        } else {
            return false
        }

    }


    return {
        getPreviewType,
        canPreview,
        canOverlaySnapPreview,
    }
}


export default usePreview